package site.jlopen.components.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;

import cn.hutool.core.io.resource.ResourceUtil;
import site.jlopen.components.entity.GraphNodeParam;

public class ComponentsReaderUtils {

	private List<GraphNodeParam> params = new ArrayList<GraphNodeParam>();

	private Map<String, GraphNodeParam> maps = new HashMap<String, GraphNodeParam>();

	public List<GraphNodeParam> getParams() {
		return params;
	}

	public Map<String, GraphNodeParam> getMaps() {
		return maps;
	}

	public GraphNodeParam getNode(String nodeCode) {
		return maps.get(nodeCode);
	}
	
	public String ioStr(InputStream is) {
        InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isr);
        try {
        	String data = null;
            StringBuilder builder = new StringBuilder();
            while((data = br.readLine()) != null) {
                builder.append(data);
            }
            return builder.toString();
		} catch (Exception e) {
			return null;
		} finally {
			try {
				br.close();
			} catch (IOException e) {}
            try {
				isr.close();
			} catch (IOException e) {}
            try {
				is.close();
			} catch (IOException e) {}
		}
    }
}
